{include file="admin/public/head"}
<form class="layui-form" style="display: inline;">
    <input type="text" name="config_key" placeholder="" class="layui-input" autocomplete="off" style="max-width: 200px;display: inline;margin: 10px 10px 0 0;height: 30px;" />
    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit="" lay-filter="vaeform">立即搜索</button>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="thumb">
    <img src='{{d.thumb}}' height="20" style="border-radius: 50%;" />
</script>
<script type="text/html" id="status">
    <i class="layui-icon {{#  if(d.status == 1){ }}layui-icon-ok{{#  } else { }}layui-icon-close{{#  } }}"></i>
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="add">添加配置</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-icon layui-icon-edit" lay-event="edit" href="javascript:;"></a>
    <a class="layui-icon layui-icon-delete" lay-event="del" href="javascript:;"></a>
</script>

{include file="admin/public/foot"}

<script>
    layui.config({
        base: '/static/admin_static/module/'
    }).use(['table','vae','form'], function(){
        var table = layui.table
            ,vae = layui.vae
            ,$ = layui.$
            ,form = layui.form;

        var tableIns = table.render({
            elem: '#test'
            ,toolbar: '#toolbarDemo'
            ,url: "{:url('admin/conf/oneindex')}" //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', align:'center'}
                ,{field: 'config_key', title: 'Key', align:'center'}
                ,{field: 'config_value', title: 'Value', align:'center'}
                ,{field: 'config_msg', title:'备注', align:'center'}
                ,{field: 'right', toolbar: '#barDemo', width:150, align:'center'}
            ]]
            ,size: "sm"
        });

        //监听事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    vae.open({
                        href:"{:url('admin/conf/addone')}",
                        title:"添加导航组",
                        end:function(){
                            tableIns.reload();
                        }
                    })
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                vae.confirm('真的删除么', function(index){
                    $.ajax({
                        url:"{:url('/admin/conf/deleteone')}",
                        data:{id:data.id},
                        success:function(res){
                            layer.msg(res.msg);
                            if(res.code==0){
                                obj.del();
                            }
                        }
                    })
                    layer.close(index);
                });
            }else if(obj.event === 'edit'){
                vae.open({
                    href:"{:url('admin/conf/editone')}?id="+data.id,
                    title:'修改导航组'+data.id,
                    end:function(){
                        tableIns.reload();
                    }
                })
            }
        });


        //监听搜索提交
        form.on('submit(vaeform)', function(data){
            tableIns.reload({where:{config_key:data.field.config_key,page:1}});
            return false;
        });
    });
</script>

</body>
</html>
